package com.cloudsigns.factorymanager2.project.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.ProduceProduceOrderBean;
import com.cloudsigns.factorymanager2.project.iview.IGetProduceOrderDetailView;
import com.cloudsigns.factorymanager2.project.model.GetProduceOrderDetailModel;
import com.cloudsigns.factorymanager2.project.model.IGetProduceOrderDetailModel;

public class GetProduceOrderDetailPresenter {
    private IGetProduceOrderDetailView view;
    private IGetProduceOrderDetailModel model;
    private Handler mHandler = new Handler();

    public GetProduceOrderDetailPresenter(IGetProduceOrderDetailView view) {
        this.view = view;
        this.model = new GetProduceOrderDetailModel();
    }

    public void getProduceOrderDetail() {
        model.getProduceOrderDetail(view.getOrderId(), new GetProduceOrderDetailModel.OnProduceOrderDetailListener() {
            @Override
            public void successed(final ProduceProduceOrderBean produceOrderBean) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProduceOrderDetailSuccessed(produceOrderBean);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProduceOrderDetailFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
